package No1_100.No21_30.ValidParentheses_20;

public class Solution {
	public static boolean isValid(String s) {
		char[] stack = new char[50];
		int i = 0,j = 0;
		while (i<s.length()) {
			switch (s.charAt(i)) {
			case '(':
				stack[j++] = '(';
				break;
			case '{':
				stack[j++] = '{';
				break;
			case '[':
				stack[j++] = '[';
				break;
			case ')':
				if (j == 0) {
					return false;
				}
				else if (stack[--j]!='(') {
					return false;
				}
				break;
			case '}':
				if (j == 0) {
					return false;
				}
				else if (stack[--j]!='{'||j<0) {
					return false;
				}
				break;
			case ']':
				if (j == 0) {
					return false;
				}
				else if (stack[--j]!='['||j<0) {
					return false;
				}
				break;
			default:
				break;
			}
			i++;
		}
		if (j==0) {
			return true;
		}
		else {
			return false;
		}
	}
	
	public static void main(String[] args) {
		if (isValid("[][")) {
			System.out.println("true");
		}
		else {
			System.out.println("false");
		}
	}
}
